﻿@{
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldData = Html.GetFieldList((string)ViewBag.Table, action, user, PageAdmin.Common.FromEnum.Member);
    string guid = Html.Guid();
}
<form method="post" id="_form" class="form" data-validate-params="beforeSubmit:'BeforeSubmit',tipsStyle:1" data-source="@Model">
    <div class="main">
        <div><b>基本信息</b></div>
        <div class="container-fluid">
            <div class="row">
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group">
                        <label class="control-label">用户名：</label>
                        <div class="controls  form-group-sm">
                            <div class="input-group">
                                <input type="text" name="Username" id="Username" readonly class="form-control" maxlength="50">
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-sm" type="button" onclick="GoMember()"><i class="fa fa-sign-in" aria-hidden="true"></i>会员中心</button>
                                </span>
                            </div>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">密码：</label>
                        <div class="controls  form-group-sm">
                            <div class="input-group">
                                <input type="text" class="form-control" maxlength="30" name="Password" id="Password" placeholder="不修改密码则留空">
                                <input type="hidden" name="oldPassword" id="oldPassword">
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-sm" type="button" onclick="Update(true)"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>更新密码</button>
                                </span>
                            </div>
                            <span class="help-block"></span>
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="control-label">用户组：</label>
                        <div class="controls  form-group-sm">
                            <div class="input-group">
                                <select class="form-control" name="MemberGroupId" id="MemberGroupId" data-source="@Html.GetCanAdminMemberGroupListJson()" data-custom-params="dataSourceFrom:'attr'"></select>
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-sm" type="button" onclick="Update()"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>更新组别</button>
                                </span>
                            </div>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">部门：</label>
                        <div class="controls  form-group-sm">
                            <div class="input-group">
                                <select class="form-control" name="DepartmentId" id="DepartmentId" data-source="@Html.GetDepartmentListJson()" data-custom-params="dataSourceFrom:'attr',isTree:true,onlySelectFinal:true">
                                    <option value="0">无</option>
                                </select>
                                <span class="input-group-btn">
                                    <button class="btn btn-default btn-sm" type="button" onclick="Update()"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>更新部门</button>
                                </span>
                            </div>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">手机：</label>
                        <div class="controls form-group-sm">
                            <div class="input-group">
                                <input type="text" class="form-control" name="Mobile" id="Mobile" data-validate="dataType:'mobile',ignoreEmpty:true,errorMsg:'手机号码格式错误！'" maxlength="15">
                                <span class="input-group-addon" id="lb_mobileState"></span>
                            </div>
                            <span class="help-block" id="_ValidateTips_Mobile"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">邮箱：</label>
                        <div class="controls  form-group-sm">
                            <div class="input-group">
                                <input type="text" class="form-control" name="Email" value="" id="Email" maxlength="50" data-validate="dataType:'email',ignoreEmpty:true,errorMsg:'邮箱地址格式错误！'">
                                <span class="input-group-addon" id="lb_emailState"></span>
                            </div>
                            <span class="help-block" id="_ValidateTips_Email"></span>
                        </div>
                    </div>

                </div>
                <div class="col-xs-12 col-sm-6">
                    <div class="form-group">
                        <label class="control-label">注册时间：</label>
                        <div class="controls  form-group-sm">
                            <input type="text" class="form-control" readonly name="RegDate" value="" id="RegDate">
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">注册IP：</label>
                        <div class="controls  form-group-sm">
                            <input type="text" class="form-control" readonly name="RegIp" id="RegIp">
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">最后登陆时间：</label>
                        <div class="controls  form-group-sm">
                            <input type="text" class="form-control" readonly name="LastDate" value="" id="LastDate">
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">最后登陆IP：</label>
                        <div class="controls form-group-sm">
                            <input type="text" class="form-control" name="LastIp" readonly value="" id="LastIp">
                            <span class="help-block"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label">登录次数：</label>
                        <div class="controls  form-group-sm">
                            <input type="text" class="form-control" readonly name="Logins" id="Logins">
                            <span class="help-block"></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="~/Incs/UEditor/ueditor.forAdmin.config.js" type="text/javascript"></script>
    <script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
    <div class="main" style="margin-top:15px" id="customField">
        <div><b>其他信息</b></div>
        @{
            string beforeSubmitJs = "";
            var data = new ViewDataDictionary();
            data.Add("from", "member");
            data.Add("guid", guid);
            data.Add("currentUser", ViewBag.CurrentUser);
            data.Add("memberGroupId", ViewBag.MemberGroupId);
            data.Add("i", 0);
            int i = 0;
            if (fieldData != null)
            {
                foreach (var row in fieldData)
                {
                    data["i"] = i;
                    beforeSubmitJs += row.BeforeSubmitJs;
                    Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                    i++;
                }
            }

        }
        @if (i == 0)
        {
            <text>
                <script>$("#customField").hide();</script></text>
        }
    </div>

    <div class="submit-footerbar">
        <label class="control-label"></label>
        <div class="controls">
            <input type="hidden" id="IsAdmin" name="IsAdmin" value="0" />
            <input type="hidden" id="State" name="State" value="1" />
            <input type="hidden" id="Logins" name="Logins" value="0" />
            <input type="hidden" id="Id" name="Id" value="0" />
            <input type="hidden" id="Guid" name="Guid" value="@guid" />
            <input type="hidden" id="EmailState" name="EmailState" value="" />
            <input type="hidden" id="MobileState" name="MobileState" value="" />
            <button type="button" class="btn btn-sm btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',callBack:'PostRefreshBack'">提交</button>
            <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
            <span class="help-block"></span>
        </div>
    </div>
</form>
<script type="text/javascript">
    function BeforeSubmit() {
         @Html.Raw(beforeSubmitJs)
        return true;
    }
    var $password = $("#Password");

    function Update(isPassword)
    {
        if (isPassword)
        {
            var pass = $password.val().Trim();
            var dataTypeFun = window["jQuery"]["ValidateDataType"]["password"];
            if (typeof (dataTypeFun) != "function") {
                alert(dataType + "数据类型未定义");
                return false;
            }
            else {
                var errorMsg = "请填写密码！";
                var hasPass = true;
                var result = dataTypeFun(pass, $password, $("#_form"));
                if (typeof (result) == "string") {
                    errorMsg = result;
                    hasPass = false;
                }
                else
                {
                    hasPass = result;
                }
                if (!hasPass)
                {
                    Msg(errorMsg);
                    $password.focus();
                    return;
                }
            }
        }
        Loading();
        var formData = $("#_form").serialize();
        Ajax({ type: "Post", url: "@Url.ActionUrl("Edit")", data: formData }, function (data) {
            data = JsonParse(data);
            var state = data.State;
            var msg = data.Msg;
            if (state == 1)
            {
                Msg("更新成功!");
            }
            else
            {
                Alert(msg)
            }
        });
        CloseLoading();
    }

    var id = Request("id");
    if (id != "") {
        $("#MemberGroupId").SelectBind();
        $("#DepartmentId").SelectBind();
        $("#_form").FormBind({ dataSourceFrom: "attr" });
        $("#oldPassword").val($("#Password").val());
        $password.val("");
        var passIcon = '<i class="fa fa-check-square-o" aria-hidden="true">已验证</i>';
        var noPassIcon = '<i class="fa fa-square-o" aria-hidden="true">未验证</i>';
        if ($("#EmailState").val() == "1")
        {
            $("#lb_emailState").html(passIcon);
        }
        else
        {
            $("#lb_emailState").html(noPassIcon);
        }
        if ($("#MobileState").val() == "1") {
            $("#lb_mobileState").html(passIcon);
        }
        else {
            $("#lb_mobileState").html(noPassIcon);
        }
    }

    function GoMember()
    {
        var uid = $("#Id").val();
        window.open("@Url.ActionUrl("GoMember")?uid=" + uid,"_blank");
    }
</script>
